package com.luxsoft.sw3.replica;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * Bitacora para entidades replicables
 * 
 * @author Ruben Cancino Ramos
 *
 */
@Entity
@Table(name="SX_REPLICA_LOG")
public class ReplicaLogRecord {
	
	@Id @GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="REPLICA_ID")
	public Long id;	
	
	@Column(name="ENTIDAD")
	public Class entityClass;
	
	@Column(name="REPLICADO")
	public Date replicado;
	
	@Column(name="TIPO",length=50,nullable=false)
	public String tipo;
	
	@Column(name="ENTITY_ID")
	public String entityId;
	
	@Column(name="CREADO")
	public Date creado;
	
	@Column(name="SUCURSAL_ID")
	public Long sucursal;
	
	public ReplicaLogRecord(){}

	public ReplicaLogRecord(Class entityClass, String entityId,	String tipo) {
		this.entityClass = entityClass;
		this.entityId = entityId;
		this.tipo = tipo;
		this.creado=new Date();
	}
	
	public String toString(){
		return ToStringBuilder.reflectionToString(this,ToStringStyle.SHORT_PREFIX_STYLE);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final ReplicaLogRecord other = (ReplicaLogRecord) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	
	
	

}
